﻿//------------------------------------------------------------------------------
// ╭─────────────────────────────╮
// │ ╭─╮     ╭─╮              TM │   ╠═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╣
// │ │ │     │ │                 │                                           ☺  
// │ │ ╰───╮ │ │ ╭─────╮ ╭─────╮ │     Name:Wedn.Net 后台处理程序基类        ♮ ♪ ♩
// │ │ ╭─╮ │ │ │ │ ╭─╮ │ │ ╭─╮ │ │                                    ♫ ♭      
// │ │ ╰─╯ │ │ │ │ ╰─╯ │ │ ╰─╯ │ │     Author:iceStone               ♬ ♪       
// │ └─────╯ └─╯ ╰─────╯ ╰───╮ │ │     Chinese:汪磊                              
// │                     ┌───╯ │ │                                              
// │                     ╰─────╯ │   ╠═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╣
// ╰─────────────────────────────╯                                              
//------------------------------------------------------------------------------
using System;
using System.Web;
using Wedn.Net.Model;
using Wedn.Net.Utility;

namespace Wedn.Net.UI.Handlers
{
    /// <summary>
    /// 后台处理程序基类
    /// </summary>
    public abstract class AdminBaseHandler : BaseHandler
    {
        private User _currentUser;
        /// <summary>
        /// 当前用户对象实体
        /// </summary>
        protected User CurrentUser
        {
            get { return _currentUser ?? (_currentUser = SessionHelper.GetSession<User>("CurrentUser")); }
        }
        /// <summary>
        /// 后台处理程序基类构造函数
        /// </summary>
        protected AdminBaseHandler()
        {
            if (!BLLFactory.BLLFactory.Instance.UserManager.CheckLogin())
            {
                //HttpContext.Current.Response.Redirect("/Login?redirect=" + StringHelper.UrlEncode(HttpContext.Current.Request.Url.ToString()));
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Write("login_timeout");
                HttpContext.Current.Response.End();
            }
            CookieHelper.SetCookie("SessionId", CookieHelper.GetCookie("SessionId"), DateTime.Now.AddMinutes(30));
        }

        /// <summary>
        /// 处理请求方法
        /// </summary>
        /// <param name="context">HTTP上下文</param>
        public abstract override void ProcessRequest(HttpContext context);
    }
}
